package itsm.isperp.module.controller.individuation;

import itsm.isperp.framework.core.context.ContextHolder;
import itsm.isperp.framework.data.domain.PageResponse;
import itsm.isperp.framework.web.controller.BaseController;
import itsm.isperp.framework.web.request.JqGridFilterRuleOp;
import itsm.isperp.framework.web.request.JqGridRequest;
import itsm.isperp.framework.web.response.ResultMessage;
import itsm.isperp.module.entity.individuation.IddDbEntityField;
import itsm.isperp.module.service.individuation.IddDbEntityFieldService;
import itsm.isperp.module.service.individuation.IddDbEntityService;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * 控制器
 * 
 * @author lizx
 * @date 2017-07-13 15:58
 */
@Controller
@RequestMapping("individuation/dbEntityField")
public class IddDbEntityFieldController extends
    BaseController<IddDbEntityField> {

  @Autowired
  protected IddDbEntityFieldService iddDbEntityFieldService;
  
  @Autowired
  protected IddDbEntityService iddDbEntityService;
  
  @Autowired
  protected JdbcTemplate jdbcTemplate;

  @Override
  public IddDbEntityFieldService getService() {
    return this.iddDbEntityFieldService;
  }

  @Override
  public String getPageTitle() {
    return "流程表单定义";
  }

  @Override
  @RequestMapping("edit")
  public ModelAndView edit(String id, HttpServletRequest req) throws Exception {
    ModelAndView mv = this.getEdit(id);
    String dbEntityId = req.getParameter("entityId");
    mv.addObject("entityId", dbEntityId);
    return mv;

  }

  @Override
  @RequestMapping("list")
  @ResponseBody
  public PageResponse<IddDbEntityField> list(JqGridRequest request,
      HttpServletRequest req) {
    String entityId = req.getParameter("entityId");
    if (StringUtils.isNotBlank(entityId))
      request.addFilterRule("db_entity_id", JqGridFilterRuleOp.eq, entityId);
    return this.getService().findAll(request).toPage();

  }
  

/*  
  @Override
  @RequestMapping("save")
  @ResponseBody
  public ResultMessage save(IddDbEntityField model, HttpServletRequest req) {
    
    String entityId=model.getDbEntityId();
    IddDbEntity iddDbEntity=iddDbEntityService.findOne(entityId);
    if(iddDbEntity!=null)
    {
      String tableName=iddDbEntity.getTableName();
      String columnName=model.getColumnName();
      String sql1="select count(1) c from idd_db_entity_field where ";
      
      String sql="ALTER TABLE "+tableName+" ADD COLUMN "+columnName+" TEXT NULL";
      jdbcTemplate.execute(sql);
      
    }
    
    this.getService().saveOrUpdate(model, req);
    return ResultMessage.newInstance(true, null, model.getId());
  }*/

}
